"""
浏览器操作
1.进入百度
2.输入柠檬班
3.进入柠檬班腾讯课堂
4.定位腾讯课堂上的元素
"""
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions

driver = webdriver.Chrome()
url = "https://www.baidu.com"
driver.get(url)

driver.implicitly_wait(3)
elem = driver.find_element(By.ID, "kw")
elem.send_keys("柠檬班腾讯课堂")
elem.send_keys(Keys.ENTER)
time.sleep(2)
all_handles = driver.window_handles

driver.find_element(By.XPATH, "//div[@id='1']//div[@class='c-container']//div//a[contains(text(),'_')]").click()
time.sleep(5)
driver.switch_to.window(driver.window_handles[1])

wait = WebDriverWait(driver, 2)
wait.until(expected_conditions.new_window_is_opened(all_handles))

